﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Eco.Actions.Runtime;
using Eco.Handles;
using Eco.ObjectRepresentation;
using Eco.Services;
using Eco.ViewModel.Runtime;
using Eco.MVC;
using EcoProject1;
using EcoProject1.ViewModelCodeGen_TicketSearch;

namespace MvcApplication1.Controllers
{
  public class ModelDrivenController : ModelDrivenControllerBase<EcoProject1EcoSpace>
    {

    static ModelDrivenController()
    {
      ModelDrivenController.ViewControllerOverride.Add("UploadAttachment", "Attachments");
    }

    public ActionResult YourInfo()
    {
      if (GlobalSingleton.IsLoggedIn(EcoSpace))
        return View("GenericView", EcoProject1.ViewModelCodeGen_User.User.Create(EcoSpace, null));
      else
        return View("GenericView", EcoProject1.ViewModelCodeGen_AccessDenied.AccessDenied.Create(EcoSpace,null));
    }
    public ActionResult Tickets()
    {
      if (GlobalSingleton.IsLoggedIn(EcoSpace))
        return View("GenericView", EcoProject1.ViewModelCodeGen_TicketSearch.TicketSearch.Create(EcoSpace, null));
      else
        return View("GenericView", EcoProject1.ViewModelCodeGen_AccessDenied.AccessDenied.Create(EcoSpace, null));
    }


        public ActionResult Index()
        {
          return View("GenericView", EcoProject1.ViewModelCodeGen_User.User.Create(EcoSpace, null));
        }

        protected override void AfterEcoSpaceCreate()
        {
          base.AfterEcoSpaceCreate();
          if (this.User.Identity is System.Web.Security.FormsIdentity && this.User.Identity.IsAuthenticated)
          {
            GlobalSingleton.InstallCurrentUserFromStringIdentifier(EcoSpace, (this.User.Identity as System.Web.Security.FormsIdentity).Name);
          }
        }


    }
}
